﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Slf;

namespace WcfLoggingService
{
  /// <summary>
  /// This logging service receives logging instructions and stores them
  /// so you can requery all logged information. The service uses SLF
  /// itself in order to just forward received logging information to an
  /// underlying logging framework. This means that the client uses SLF to
  /// log to this service, while the service logs to SLF to store the logged
  /// data.
  /// For the simplicity of the sample, SLF was configured with a TestLogger
  /// (see Global.asax.cs for initialization code).
  /// </summary>
  public class LoggingService : ILoggingService
  {
    /// <summary>
    /// This sample only provides a simplified API.
    /// </summary>
    public void Log(LogLevel level, string message)
    {
      //create log item
      LogItem item = new LogItem {LogLevel = level, Message = message};

      //submit to SLF
      ILogger logger = LoggerService.GetLogger(); 
      logger.Log(item);
    }


    /// <summary>
    /// Returns all items that were logged so far.
    /// </summary>
    /// <returns></returns>
    public List<LogItem> GetLoggedItems()
    {
      //we know we used a test logger...
      TestLogger logger = (TestLogger) LoggerService.GetLogger();
      return logger.LoggedItems;
    }
  }
}
